package com.vagavaga.tx;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.sql.Connection;

/**
 * This is utility class that contains references to transactional methods
 * of {@link Connection}.
 *
 * @author <code>river</code>
 * @version $Revision: 1.2 $ $Date: 2004/11/07 00:00:27 $
 */
abstract class TxInterceptor implements InvocationHandler {
    /**
     * Reference to setIsolationLevel(int) method.
     */
    static final Method SET_ISOLATION_METHOD;

    /**
     * Reference to {@link Connection#setAutoCommit} method.
     */
    static final Method AUTOCOMMIT_METHOD;
    /**
     * Reference to {@link Connection#commit} method.
     */
    static final Method COMMIT_METHOD;
    /**
     * Reference to java.sql.Connection rollback method.
     */
    static final Method ROLLBACK_METHOD;
    /**
     * Reference to close() method.
     */
    static final Method CLOSE_METHOD;

    static {
        try {
            SET_ISOLATION_METHOD = Connection.class.getMethod(
                    "setTransactionIsolation", new Class[] {
                    int.class});
            AUTOCOMMIT_METHOD = Connection.class.getMethod(
                    "setAutoCommit", new Class[] {
                    boolean.class});
            COMMIT_METHOD = Connection.class.getMethod(
                    "commit", (Class[]) null);
            ROLLBACK_METHOD = Connection.class.getMethod(
                    "rollback", (Class[]) null);
            CLOSE_METHOD = Connection.class.getMethod(
                    "close", (Class[]) null);
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }

}
